﻿<!--#include file="../lib/base.asp"-->
<!--#include file="../theme.asp"-->
<%
	sdcms.checkuserlogin
	dim classid:classid=sdcms.getint(sdcms.fget("classid",0),0)
	dim field_data:field_data=sdcms.get_model_field(1)
	
		function get_self_field(byval t0,byval t1,byval t2,byval t3,byval t4,byval t5,byval t6,byval t7,byval t8,byval t9,byval t10,byval t11,byval t12)
	dim str:str=""
	t8=sdcms.iif(isnull(t8),"",t8)
	if t6=1 then
		dim rule,bitian
		rule="bitian"
		bitian=" <font color=""#ff0000"" >*</font>"
	end if
	dim i,arr,m
	arr=split(t5,vbcrlf)
	select case t2
	case "1"
		select case t3
			case "2":t4=10
			case "3":t4=50:t8=replace(t8,"/","-")
			case "4":t4=255
			case "5":t4=10
			if t8<>"" then t8=formatnumber(t8,-1,-1)
		end select
		str=str&"<input type=""text"" name="""&t0&""" id="""&t0&""" size=""50"" value="""&t8&""" maxlength="""&t4&""" class=""form-control "&rule&""" />"&bitian
		if t3=4 then
			str=str&"<input type=""button"" value=""上传"" config="""&t0&":"&t9&":"&t10&":1"" class=""bnt bnt_save"" />"
		end if
	case "3"
		str=str&"<select data-style=""btn btn-primary btn-sm"" data-live-search=""true""  name="""&t0&""" id="""&t0&""" class=""selectpicker "&rule&""">"&vbcrlf
		str=str&"<option value="""">请选择"&t1&"</option>"&vbcrlf
		for i=0 to ubound(arr)
			if len(arr(i))>0 then
				if instr(arr(i),"|")>0 then
					m=split(arr(i),"|")
					str=str&"<option value="""&m(1)&""" "
					if m(1)=t8 then
						str=str&" selected"
					end if
					str=str&">"&m(0)&"</option>"&vbcrlf
				end if
			end if
		next
		str=str&"</select>"&bitian
	case "4","5"
		dim types:types=sdcms.iif(t2=4,"radio","checkbox")
		dim j:j=0
		for i=0 to ubound(arr)
			if len(arr(i))>0 then
				if instr(arr(i),"|")>0 then
					m=split(arr(i),"|")
					str=str&"<input type="""&types&""" name="""&t0&""" id="""&t0&"_"&i&""" value="""&m(1)&""" "
					if j=0 then
						str=str&" class="" "&rule&""" "
					end if
					if t2=4 then
						if m(1)=t8 then
							str=str&" checked"
						end if
					else
						if instr(", "&t8&", ",", "&m(1)&", ")>0 then
							str=str&" checked"
						end if
					end if
					str=str&">"&m(0)&""&vbcrlf
					j=j+1
				end if
			end if
		next
	case "2","6"
		str=str&"<textarea name="""&t0&""" id="""&t0&""" "
		str=str&"class=""form-control "&rule&""" cols=""51"" rows=""6"" placeholder="""&t11&""" data-toggle=""popover""  lang="""&t11&""" data-placement=""top""  title="""&t11&"""  data-trigger=""hover"" "
		str=str&">"&t8&"</textarea>"&bitian
   case "7"
   dim btext,upimg,imgtemp
   btext=""
   upimg=""
   imgtemp=""
   if instr(t8,"##")>0 then
   dim temp:temp=split(t8,"##")
   btext=temp(0)
   upimg=temp(1)
   if len(upimg)>0 then
   imgtemp="<img src="""&upimg&""" width=""30"" height=""30"" />"
   end if
   end if
  str=str&"<div class=""form-group""><div class=""col-lg-12 col-sm-12""><textarea class=""form-control btext"" rows=""6"" placeholder="""&t11&""" data-toggle=""popover""  lang="""&t11&""" data-placement=""top""  title="""&t11&"""  data-trigger=""hover"">"&btext&"</textarea></div></div><div class=""form-group""><div class=""col-lg-12 col-sm-12""><input type=""hidden"" id="""&t0&""" name="""&t0&""" size=""50"" maxlength=""255"" class=""ip hinput"" value="""&t8&""" /><input type=""hidden"" id="""&t0&"pic"" name="""&t0&"pic"" size=""50"" maxlength=""255"" class=""ip upimg"" value="""&upimg&""" /><div class=""showlitpic"">"&imgtemp&"</div><button type=""button"" class=""btn btn-primary pull-left bnt"" config="""&t0&"pic:1:0:1"">上传附件</button></div></div>"
	case "8"
	str=str&"<div class=""zlfa""><input type=""hidden""  value="""&t8&""" name="""&t0&""" id="""&t0&""" >"
	str=str&"方案一：<textarea name="""&t0&"01"" id="""&t0&"01"" "
	str=str&"style=""width:98%;"""
	str=str&">"&t8&"</textarea><br/>"

	str=str&"方案二：<textarea name="""&t0&"02"" id="""&t0&"02"" "
	str=str&"style=""width:98%;"""
	str=str&">"&t8&"</textarea><br/>"

	str=str&"方案三：<textarea name="""&t0&"03"" id="""&t0&"03"" "
	str=str&"style=""width:98%;"""
	str=str&">"&t8&"</textarea><br/>"

	str=str&"方案四：<textarea name="""&t0&"04"" id="""&t0&"04"" "
	str=str&"style=""width:98%;"""
	str=str&">"&t8&"</textarea><br/>"
	
	str=str&"您的治疗方案：<select class=""text_input"" id=""selectfa""><option value="""">请选择</option><option value=""1"">方案一</option><option value=""2"">方案二</option><option value=""3"">方案三</option><option value=""4"">方案四</option></select></div>"
	
   case "9"
   btext=""
   upimg=""
   temp=""
   if instr(t8,"##")>0 then
   temp=split(t8,"##")
   btext=temp(0)
   upimg=temp(1)
   if len(upimg)>0 then
   imgtemp="<img src="""&upimg&""" width=""30"" height=""30"" />"
   end if
   end if
 str=str&"<div class=""form-group""><label for=""inputPassword3"" class=""col-lg-3 col-md-3 col-sm-4 control-label"">"&t1&"</label><div class=""col-lg-7 col-sm-7""><textarea class=""form-control btext"" rows=""6"" placeholder="""&t11&""" data-toggle=""popover""  lang="""&t11&""" data-placement=""top""  title="""&t11&"""  data-trigger=""hover"">"&btext&"</textarea></div></div><div class=""form-group""><div class=""col-lg-offset-3 col-md-offset-3 col-sm-offset-4 col-lg-7 col-sm-7""><input type=""hidden"" id="""&t0&""" name="""&t0&""" size=""50"" maxlength=""255"" class=""ip hinput"" value="""&t8&""" /><input type=""hidden"" id="""&t0&"pic"" name="""&t0&"pic"" size=""50"" maxlength=""255"" class=""ip upimg"" value="""&upimg&""" /><div class=""showlitpic"">"&imgtemp&"</div><button type=""button"" class=""btn btn-primary pull-left bnt"" config="""&t0&"pic:1:0:1"">上传附件</button></div></div>"
end select
	get_self_field=str
end function

function deal_model_field(byval t0)
	dim a:a=sdcms.get_model_field(t0)
	if not isarray(a) then
		deal_model_field="":exit function
	end if
	dim fi,fstr,istrim,length,fname,fmode,iscn,formstr,rules
	for fi=0 to ubound(a,2)
		fstr=fstr&","
		fname=a(0,fi)
		istrim=a(10,fi)
		length=a(5,fi)
		fmode=a(3,fi)
		iscn=1
		rules=""
		select case a(2,fi)
			case "1"
				select case fmode
					case "2","5":length=10:iscn=0
					case "3":length=50
				end select
				formstr="sdcms.enhtml(sdcms.fpost("""&fname&""","&istrim&"))"
			case "2":length=0
				formstr="sdcms.enhtml(sdcms.fpost("""&fname&""","&istrim&"))"
			case "3","4","5":length=255
				formstr="sdcms.enhtml(sdcms.fpost("""&fname&""","&istrim&"))"
			case "6","7","8","9":length=0
				formstr="sdcms.fpost("""&fname&""","&istrim&")"
		end select
		fstr=fstr&"array("""&fname&""","&formstr&","&length&","&iscn&")"
		formstr=eval(formstr)
		if a(8,fi)=1 then
			if sdcms.strlen(formstr)=0 then sdcms.ajaxjson a(1,fi)&"不能为空",0:sdcms.die
			select case a(9,fi)
				case "2":rules="int"
				case "3":rules="price"
				case "4":rules="tel"
				case "5":rules="mobile"
				case "6":rules="email"
				case "7":rules="date"
				case "8":rules="zipcode"
				case "9":rules="qq"
				case "10":rules="url"
			end select
			if rules<>"" then
				if not(sdcms.checkstr(formstr,rules)) then
					sdcms.ajaxjson a(1,fi)&"格式错误",0:sdcms.die
				end if
			end if
		end if
	next
	deal_model_field=fstr
end function
	
	dim data
	dim catedata,catename,modeid
	catedata=sdcms.getclassdb(classid)
	if not isarray(catedata) then
		sdcms.echo "&#26639;&#30446;&#19981;&#23384;&#22312;&#25110;&#24050;&#34987;&#21024;&#38500;"
		sdcms.die
	end if
	catename=catedata(1)
	modeid=catedata(10)
	if catedata(31)=0 then
		sdcms.echo "&#26639;&#30446;&#31105;&#27490;&#25237;&#31295;"
		sdcms.die
	end if
	dim theme_publish_add:theme_publish_add=catedata(29)
	dim userdata,userid,username,loginbase
	userdata=sdcms.userinfo
	userid=userdata(0)
	username=userdata(1)
	loginbase=sdcms.base64encode(userdata(1)&userdata(2))
	dim is_lock:is_lock=sdcms.db.dbloadone("allowpostverify","sd_user_group","id="&userdata(4)&"")
	dim brand:brand=sdcms.get_user(userid,"my_brand")
	if len(brand)<=0 then
	sdcms.go webroot&"user/brand.asp?msg="&server.urlencode("请先填写您的品牌信息")&"&url="&thisurl
	end if
	sub adddb()
		dim t0,t1,data,t29,t30,t40
		dim u0,u1
		t0=sdcms.enhtml(sdcms.fpost("t0",0))
	    t1=sdcms.enhtml(sdcms.fpost("t1",0))
	    t29=sdcms.enhtml(sdcms.fpost("t29",0))

	    t30=sdcms.enhtml(sdcms.fpost("t30",0))
	    t40=sdcms.enhtml(sdcms.fpost("t40",0))
		t29=replace(t29," ","")
		t30=replace(t30," ","")
		t40=replace(t40," ","")
		dim pic
		pic=split(t40,",")	
		
		t40=replace(t40,",",""",""")
	
		t40="array("""&t40&""")"
		if sdcms.strlen(t0)=0 then
			sdcms.ajaxjson "&#20135;&#21697;&#21517;&#31216;&#19981;&#33021;&#20026;&#31354;",0
			exit sub
		end if
		if sdcms.strlen(t1)=0 then
			sdcms.ajaxjson "&#20135;&#21697;&#25551;&#36848;&#19981;&#33021;&#20026;&#31354;",0
			exit sub
		end if

		t1=sdcms.replacetext(t1,"("&blacklist&")",string(len("&$1&"),"*"))
		u0=sdcms.get_intro(t1)
	
			
		u1=sdcms.iif(is_lock=0,-1,1)
		dim cid:cid=sdcms.getint(sdcms.fget("id",0),0)
		dim fstr:fstr=deal_model_field(modeid)
		if cid=0 then
			select case sdcms.user_publish_num
				case "-1"
					sdcms.ajaxjson "&#24744;&#36824;&#26410;&#21462;&#24471;&#21457;&#24067;&#20135;&#21697;&#36164;&#26684;&#65292;&#35831;&#32852;&#31995;&#31649;&#29702;&#21592;&#24320;&#36890;",0:exit sub
				case "0"
					sdcms.ajaxjson "&#24744;&#20170;&#26085;&#19978;&#20256;&#20135;&#21697;&#25968;&#37327;&#24050;&#29992;&#23436;",0:exit sub
			end select
			data=array(array("title",t0,255),array("hits",0,10),array("islock",u1,0),array("isnice",0,1),array("ontop",0,1),array("iscomment",1,1),array("createdate",now(),50),array("likeid","0",0),array("ispic",1,1),array("pic",pic(0),255,1),array("lastupdate",now(),50),array("classid",classid,0),array("isurl",0,1),array("comments",0,0),array("adminid",0,0),array("userid",userid,0),array("author",username,50),array("intro",u0,0),array("point",0,10))
            if sdcms.db.dbnew("sd_content",data,"")=1 then
	        end if
	
			cid=sdcms.db.insertid("id","sd_content")
			
fstr="array(array(""cid"",cid,0,0),array(""content"",t1,0,1),array(""downway"",t29,0,1),array(""downurl"",t30,0,1),array(""piclist"",t40,0,1),array(""Manufacturer"",brand,0,1)"&fstr&")"
			sdcms.db.insert "sd_model_news",eval(fstr)
			sdcms.deal_user_attachment userid,cid
			sdcms.deal_content_url cid,classid
			if u1=1 then sdcms.deal_user_publish_point cid,userid
		else
			dim edata:edata=sdcms.db.dbload(1,"title","sd_content","id="&cid&" and islock<0 and userid="&userid&"","")
			if ubound(edata)>=0 then
				data=array(array("title",t0,255,1),array("intro",u0,0,1))
				sdcms.db.dbupdate "sd_content","id="&cid&"",data
fstr="array(array(""cid"",cid,0,0),array(""content"",t1,0,1),array(""downway"",t29,0,1),array(""downurl"",t30,0,1),array(""piclist"",t40,0,1),array(""Manufacturer"",brand,0,1)"&fstr&")"
				sdcms.db.dbupdate "sd_model_news","cid="&cid&"",eval(fstr)
				sdcms.deal_user_attachment userid,cid
			end if
		end if
		sdcms.ajaxjson "&#20135;&#21697;&#21457;&#24067;&#25104;&#21151;",1
	end sub
	
	dim act:act=lcase(sdcms.fget("act",0))
	select case act
		case "db":adddb
		case else
			dim id:id=sdcms.getint(sdcms.fget("id",0),0)
			
			if id>0 then
				dim edata:edata=sdcms.db.dbload(1,"title","sd_content","id="&id&" and islock<0 and userid="&userid&"","")
				if ubound(edata)<0 then
					id=0
				else
					dim title,content
					title=edata(0,0)
					dim cdata:cdata=sdcms.db.dbload(1,"content","sd_model_news","cid="&id&"","")
					if ubound(cdata)>=0 then
						content=cdata(0,0)
					end if
				end if
			end if
			sdcms.show theme_publish_add,""
	end select
	sdcms.db.dbclose
%>